package com.leilei.model;

import com.leilei.model.Point;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created by zl206 on 2016/11/6.
 */
public class Tool {
    public static String color(){
        return  "#"+get()+get()+get();
    }

    private static String get(){

        return String.format("%02x",new Random().nextInt(0xaa));
    }
    public static boolean isClose(Point p1, Point p2, double l){
        if(getL(p1,p2)<l)return true;
        return false;
    }
    public static boolean isIn(Point p1, Point p2, double l1, double l2){
        double l=getL(p1,p2);
        if(l>l1&&l<l2)return true;
        return false;
    }
    public static double getL(Point p1, Point p2){
        double dx=p2.getX()-p1.getX();
        double dy=p2.getY()-p1.getY();
        return Math.sqrt(dx*dx+dy*dy);
    }


    public static void forward(Point p1, double l, double r){
        p1.setX(p1.getX()+l*Math.cos(r));
        p1.setY(p1.getY()+l*Math.sin(r));
    }

    public static Point forwardP(Point p1,double l, double r){
        double x=p1.getX()+l*Math.cos(r);
        double y=p1.getY()+l*Math.sin(r);
        Point point = new Point();
        point.setX(x);
        point.setY(y);
        return point;
    }

    public static double getAngle(Point p1, Point p2){
        double dx=p2.getX()-p1.getX();
        double dy=p2.getY()-p1.getY();
        return Math.atan2(dy, dx);
    }

}
